home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c
- Subject: Re: How to dynamically allocate first element of linked list.
- Date: Thu, 11 Jan 1996 13:22:31 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d33b7$kg3@tahko.lpr.carel.fi>
- References: <erkDL007G.rt@netcom.com>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- erk@netcom.com (Staugher) wrote:
-
- >Im trying (without any luck )to write a function to allocate the first element
- >of a doubly linked list in C++. Unfortunately I learned data structures in
- >Pascal and have to port my knowledge (or lack of ) to C.
-
- >Here is my arrangement:
-
- [stuff deleted]
-
- >struct elmnt * newlist(void)
- >{
- >struct elmnt *newptr;
- >newptr = malloc(sizeof(struct elmnt));
- >return (newptr);
- >}
-
- >//=======================================
-
- >The compiler complains with an ERROR that it cannot convert
- >(void *) to (elmnt *) in function newlist
-
- >I hope that the problem is obvious to someone :/
-
- >ADV thanks ANCE
-
- C++ uses strong type checking, which is why your code won't compile
- (malloc returns a void*, whereas newptr wants struct elmnt*.
- Correction is to write:
-
- newptr = (struct elmnt *)malloc(sizeof(struct elmnt));
-
- Later,
- AriL
-
- All my opinions are mine and mine alone.
-
-